package com.huike.clues.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.constant.HttpStatus;
import com.huike.common.constant.ScheduleConstants;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import java.util.Date;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper tbClueMapper;

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Override
    public int insertTbClueTrackRecord(ClueTrackRecordVo clueTrackRecordVo) {
        // 修改线索
        TbClue clue = new TbClue();
        BeanUtil.copyProperties(clueTrackRecordVo, clue, "id");
        clue.setId(clueTrackRecordVo.getClueId());
        clue.setCreateBy(SecurityUtils.getUsername());
        clue.setCreateTime(DateUtils.getNowDate());
        tbClueMapper.updateTbClue(clue);

        // 添加线索跟进记录
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        BeanUtil.copyProperties(clueTrackRecordVo, tbClueTrackRecord);
        tbClueTrackRecord.setType("0");
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());

        return tbClueTrackRecordMapper.insertTbClueTrackRecord(tbClueTrackRecord);
    }

    @Override
    public TableDataInfo selectTbClueTrackRecordListByClueId(Long clueId) {
        TableDataInfo dataInfo = new TableDataInfo();
        List<TbClueTrackRecord> clueTrackRecordList = tbClueTrackRecordMapper.selectTbClueTrackRecordListByClueId(clueId);
        dataInfo.setTotal(clueTrackRecordList.size());
        dataInfo.setRows(clueTrackRecordList);
        dataInfo.setCode(HttpStatus.SUCCESS);
        dataInfo.setMsg("查询成功!");
        return dataInfo;
    }

}
